package com.hilaver.dzmis.service.impl;

import java.util.List;
import java.util.Locale;
import java.util.Set;

import com.hilaver.dzmis.Constants;
import com.hilaver.dzmis.basicinfo.BiMeasureSpecification;
import com.hilaver.dzmis.basicinfo.BiMeasureSpecificationItem;
import com.hilaver.dzmis.basicinfo.BiYarn;
import com.hilaver.dzmis.codetable.CtAccessoryType;
import com.hilaver.dzmis.codetable.CtApplicationType;
import com.hilaver.dzmis.codetable.CtArmor1Type;
import com.hilaver.dzmis.codetable.CtArmorSet;
import com.hilaver.dzmis.codetable.CtArmorType;
import com.hilaver.dzmis.codetable.CtCollarType;
import com.hilaver.dzmis.codetable.CtDesignType;
import com.hilaver.dzmis.codetable.CtMsiDescription;
import com.hilaver.dzmis.codetable.CtProductIdentificationStyle;
import com.hilaver.dzmis.codetable.CtSeasonNumber;
import com.hilaver.dzmis.codetable.CtStature;
import com.hilaver.dzmis.codetable.CtSupplyType;
import com.hilaver.dzmis.codetable.CtYarnMaterial;
import com.hilaver.dzmis.codetable.CtYarnMeasure;
import com.hilaver.dzmis.dao.ProductIdentificationDAO;
import com.hilaver.dzmis.order.OrderColorTest;
import com.hilaver.dzmis.product.ProductAccessoryButton;
import com.hilaver.dzmis.product.ProductAccessoryHang;
import com.hilaver.dzmis.product.ProductAccessoryOthers;
import com.hilaver.dzmis.product.ProductAccessoryZip;
import com.hilaver.dzmis.product.ProductDZColor;
import com.hilaver.dzmis.product.ProductIdentification;
import com.hilaver.dzmis.product.ProductLaunching;
import com.hilaver.dzmis.product.ProductMeasureSpecificationItem;
import com.hilaver.dzmis.service.BasePDFService;
import com.hilaver.dzmis.util.StringUtils;
import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.FontSelector;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;

public class PDFExportServiceImpl1 extends BasePDFService {

	private ProductIdentificationDAO dao;

	private BiDZColorServiceImpl colorServiceImpl;

	private CtServiceImpl ctService;

	private Document document;
	
	private String input;
	
	public PDFExportServiceImpl1(Document document, Locale locale) {
		super.locale = locale;
		this.dao = new ProductIdentificationDAO();
		this.colorServiceImpl = new BiDZColorServiceImpl();
		this.ctService = new CtServiceImpl();
		super.i18n = new I18nServiceImpl();
		this.document = document;
		this.setPageConfig();
	}
	
	public void exportProductionIdentification(Integer id) throws Exception {
		ProductIdentification pi = (ProductIdentification) this.dao.get(
				ProductIdentification.class.getName(), id);

		// 1st page
		document.add(this.getHeader());
		document.add(this.getPiTitleTable(pi));
		document.add(this.getPiTitleTable11(pi));
		document.add(this.getPiTitleTable12(pi));
		document.add(this.getPiTitleTable13(pi));
		document.add(this.getPiTitleTable14(pi));
		document.add(this.getPiTitleTable15(pi));
		document.add(this.getPiTitleTable16(pi));
		
		document.newPage();
		
		if(pi.getSketch4() != null){
			StringUtils.writeFile(super.realFileDir
					+ pi.getSketch4Name(), pi.getSketch4());
			document.add(this.getHeader());
			float[] widthsTitle = { 1f};
			PdfPTable table = new PdfPTable(widthsTitle);
			table.setWidthPercentage(100);
			table.setSpacingBefore(5);
			table.addCell(getTableCell(new String[]{"ui.productidentification.sketch", "4"}, Rectangle.TOP, 1));
			PdfPCell cell = new PdfPCell(Image.getInstance(super.realFileDir
					+ pi.getSketch4Name()), true);
			cell.setPaddingTop(5);
			cell.setPaddingLeft(20);
			cell.setPaddingRight(20);
			cell.setPaddingBottom(5);
			cell.setBorder(Rectangle.BOTTOM);
			table.addCell(cell);
			document.add(table);
			document.newPage();
		}
		
		//if("tc".equals(input)){
		if(pi.getBiMeasureSpecification() != null){
			document.add(this.getHeader());
			document.add(this.getPiTitleTable(pi));
			//document.add(this.getPiTitleTable21(pi));
			document.add(this.getHeader(pi.getBiMeasureSpecification()));
			document.add(this.getSkeletonImg(pi.getBiMeasureSpecification()));
			document.add(this.getBiMeasureSpecificationTable(pi));
			
			document.newPage();
		}
			document.add(this.getHeader());
			document.add(this.getPiTitleTable(pi));
			document.add(this.getTrimmingListTable(pi));
			
			document.newPage();
			
			document.add(this.getHeader());
			document.add(this.getPiTitleTable(pi));
			document.add(this.getTrimmingTable(pi));
		//}
	}
	
	private void setPageConfig(){
		this.document.setPageSize(PageSize.A4);
		this.document.setMargins(10, 10, 0, 35);
		this.selector = new FontSelector();
		this.boldSelector = new FontSelector();
		// selector.addFont(FontFactory.getFont(FontFactory.COURIER, 10));
		selector.addFont(FontFactory.getFont("Arial", 8));
		selector.addFont(FontFactory.getFont("STSong-Light", "UniGB-UCS2-H",
				BaseFont.NOT_EMBEDDED, 8));
		boldSelector.addFont(FontFactory.getFont("Arial", 8,Font.BOLD));
		boldSelector.addFont(FontFactory.getFont("STSong-Light", "UniGB-UCS2-H",
				BaseFont.NOT_EMBEDDED, 8,Font.BOLD));
	}
	
	private PdfPTable getHeader() throws Exception{
		float[] widthsTitle = { 0.3f, 0.7f,};
		PdfPTable table = new PdfPTable(widthsTitle);
		table.setWidthPercentage(100);
		table.setSpacingBefore(1);
		PdfPCell cellLeft = new PdfPCell();
		cellLeft.setVerticalAlignment(Paragraph.ALIGN_LEFT);
		cellLeft.setMinimumHeight(20);
		cellLeft.setBorder(Rectangle.NO_BORDER);
		cellLeft.setImage(Image.getInstance(super.realFileDir
				+ "dzltd.png"));
		table.addCell(cellLeft);
		
		PdfPCell cellRight = new PdfPCell(new Paragraph(""));
		cellRight.setBorder(Rectangle.NO_BORDER);
		table.addCell(cellRight);
		return table;
	}
	
	private PdfPTable getPiTitleTable(ProductIdentification pi)
		throws Exception {
		// first page
		float[] widthsTitle = { 2f, 2.5f, 2.0f, 1.0f, 1.5f };
		PdfPTable table = new PdfPTable(widthsTitle);
		table.setWidthPercentage(100);
		table.setSpacingBefore(2);
		//1st row
		table.addCell(getTableCell("ui.productidentification.style", false, 1));
		table.addCell(getTableCellBold(new String[] {
				this.ctService.getDescription(CtCollarType.class.getName(), pi
						.getCtCollarType(), locale),
				this.ctService.getDescription(
						CtProductIdentificationStyle.class.getName(), pi
								.getCtProductIdentificationStyle(), locale) },
								false, 1));
		table.addCell(getEmptyLine(1));
		table.addCell(getTableCell("ui.productidentification.seasonnumber",
				false, 1));
		table.addCell(getTableCellBold(
				this.ctService.getDescription(CtSeasonNumber.class.getName(),
						pi.getCtSeasonNumber(), locale), false, 1));
		//2nd row
		table.addCell(getEmptyLine(3));
		table.addCell(getTableCell("ui.reference.reference", false, 1));
		table.addCell(getTableCellBold(pi.getReference(), false, 1));
		return table;
	}
	
	private PdfPTable getPiTitleTable11(ProductIdentification pi)
		throws Exception {
		// first page
		float[] widthsTitle = { 2.0f, 2.0f, 2.0f, 2.0f, 1.5f, 2.0f, 2.0f };
		PdfPTable table = new PdfPTable(widthsTitle);
		table.setWidthPercentage(100);
		table.setSpacingBefore(1);
		//1st row
		table.addCell(getTableCell("ui.francecustomer.name", false, 1));
		table.addCell(getTableCellBold(pi.getBiFranceCustomer().getName(), false, 1));
		table.addCell(getTableCell("ui.francecustomer.department", false, 1));
		table.addCell(getTableCellBold(pi.getBiFranceCustomer().getDepartment(), false, 1));
		table.addCell(getEmptyLine(1));
		table.addCell(getTableCell(new String[] { "message.edit.createdate",
		"(d/m/Y)" }, false, 1));
		table.addCell(getTableCellBold(StringUtils.toString(pi.getCreateDate()),
				false, 1));
		//2nd row
		table.addCell(getTableCell("ui.productidentification.designtype", false, 1));
		table.addCell(getTableCellBold(this.ctService.getDescription(CtDesignType.class.getName(), pi.getCtDesignType(),locale), false, 1));
		table.addCell(getTableCell("ui.productidentification.chartversion", false, 1));
		table.addCell(getTableCellBold(pi.getCtDesignType(), false, 1));
		table.addCell(getEmptyLine(3));
		return table;
	}
	
	private PdfPTable getPiTitleTable12(ProductIdentification pi)
		throws Exception {
		// first page
		float[] widthsTitle = { 2.0f, 2.0f, 2.0f, 2.0f, 1.5f, 2.0f, 2.0f };
		PdfPTable table = new PdfPTable(widthsTitle);
		table.setWidthPercentage(100);
		table.setSpacingBefore(1);
		//1st row
		table.addCell(getTableCell("ui.factory.name", 1, Rectangle.TOP));
		
		PdfPCell cell2 = null;
		if(locale.equals(Constants.LOCALE_TYPE_ZH)){
			cell2 = getTableCellBold(pi.getBiFactory().getNameCN(), false, 6, Paragraph.ALIGN_LEFT);
		}else{
			cell2 = getTableCellBold(pi.getBiFactory().getNameEN(), false, 6, Paragraph.ALIGN_LEFT);
		}
		cell2.setBorder(Rectangle.TOP);
		table.addCell(cell2);
		
		//2nd row
		table.addCell(getTableCell("ui.reference.machinetype", 1, Rectangle.BOTTOM));
		table.addCell(getTableCellBold("ui.factory." + pi.getEquipment(), 1, Rectangle.BOTTOM));
		table.addCell(getTableCell("ui.factory.jauge", 1,Rectangle.BOTTOM));
		
		table.addCell(getTableCellBold(pi.getJauge(), 1, Rectangle.BOTTOM));
		
		table.addCell(getEmptyLine(3, Rectangle.BOTTOM));
		return table;
	}
	
	private PdfPTable getPiTitleTable13(ProductIdentification pi)
	throws Exception {
		// first page
		float[] widthsTitle = { 1.2f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f };
		PdfPTable table = new PdfPTable(widthsTitle);
		table.setWidthPercentage(100);
		table.setSpacingBefore(5);
		//1st row
		table.addCell(getTableCell("ui.armor.armor", 1, Rectangle.TOP));
		table.addCell(getTableCell("ui.reference.front", 1, Rectangle.TOP));
		table.addCell(getTableCell("ui.reference.back", 1, Rectangle.TOP));
		table.addCell(getTableCell("ui.reference.sleeves", 1, Rectangle.TOP));
		table.addCell(getTableCell("ui.reference.bottomthrum", 1, Rectangle.TOP));
		table.addCell(getTableCell("ui.reference.sleevesthrum", 1, Rectangle.TOP));
		table.addCell(getTableCell("ui.reference.necklinethrum", 1, Rectangle.TOP));

		//2nd row
		table.addCell(getEmptyLine(1, Rectangle.NO_BORDER));
		String front = "";
		if (pi.getFront() != null) {
			front += this.ctService.getDescription(CtArmorType.class.getName(),
					pi.getFront().getCtArmorType(), locale)
					+ " ";
			front += this.ctService.getDescription(
					CtArmor1Type.class.getName(), pi.getFront()
							.getCtArmor1Type(), locale)
					+ " ";
			front += pi.getFront().getArmorTypeE() == null ? "" : (pi
					.getFront().getArmorTypeE() + " ");
			front += this.ctService.getDescription(CtArmorSet.class.getName(),
					pi.getFront().getCtArmorSet(), locale)
					+ " ";
		}
		table.addCell(getTableCellBold(front, 1, Rectangle.NO_BORDER));
		
		String back = "";
		if (pi.getBack() != null) {
			back += this.ctService.getDescription(CtArmorType.class.getName(),
					pi.getBack().getCtArmorType(), locale)
					+ " ";
			back += this.ctService.getDescription(
					CtArmor1Type.class.getName(), pi.getBack()
							.getCtArmor1Type(), locale)
					+ " ";
			back += pi.getBack().getArmorTypeE() == null ? "" : (pi
					.getBack().getArmorTypeE() + " ");
			back += this.ctService.getDescription(CtArmorSet.class.getName(),
					pi.getBack().getCtArmorSet(), locale)
					+ " ";
		}
		table.addCell(getTableCellBold(back, 1, Rectangle.NO_BORDER));
		
		String sleeves = "";
		if (pi.getSleeves() != null) {
			sleeves += this.ctService.getDescription(CtArmorType.class.getName(),
					pi.getSleeves().getCtArmorType(), locale)
					+ " ";
			sleeves += this.ctService.getDescription(
					CtArmor1Type.class.getName(), pi.getSleeves()
							.getCtArmor1Type(), locale)
					+ " ";
			sleeves += pi.getSleeves().getArmorTypeE() == null ? "" : (pi
					.getSleeves().getArmorTypeE() + " ");
			sleeves += this.ctService.getDescription(CtArmorSet.class.getName(),
					pi.getSleeves().getCtArmorSet(), locale)
					+ " ";
		}
		table.addCell(getTableCellBold(sleeves, 1, Rectangle.NO_BORDER));
		
		String bottomthrum = "";
		if (pi.getBottomThrum() != null) {
			bottomthrum += this.ctService.getDescription(CtArmorType.class.getName(),
					pi.getBottomThrum().getCtArmorType(), locale)
					+ " ";
			bottomthrum += this.ctService.getDescription(
					CtArmor1Type.class.getName(), pi.getBottomThrum()
							.getCtArmor1Type(), locale)
					+ " ";
			bottomthrum += pi.getBottomThrum().getArmorTypeE() == null ? "" : (pi
					.getBottomThrum().getArmorTypeE() + " ");
			bottomthrum += this.ctService.getDescription(CtArmorSet.class.getName(),
					pi.getBottomThrum().getCtArmorSet(), locale)
					+ " ";
		}
		table.addCell(getTableCellBold(bottomthrum, 1, Rectangle.NO_BORDER));
		
		String sleevesthrum = "";
		if (pi.getSleevesThrum() != null) {
			sleevesthrum += this.ctService.getDescription(CtArmorType.class.getName(),
					pi.getSleevesThrum().getCtArmorType(), locale)
					+ " ";
			sleevesthrum += this.ctService.getDescription(
					CtArmor1Type.class.getName(), pi.getSleevesThrum()
							.getCtArmor1Type(), locale)
					+ " ";
			sleevesthrum += pi.getSleevesThrum().getArmorTypeE() == null ? "" : (pi
					.getSleevesThrum().getArmorTypeE() + " ");
			sleevesthrum += this.ctService.getDescription(CtArmorSet.class.getName(),
					pi.getSleevesThrum().getCtArmorSet(), locale)
					+ " ";
		}
		table.addCell(getTableCellBold(sleevesthrum, 1, Rectangle.NO_BORDER));
		
		String necklinethrum = "";
		if (pi.getNecklineThrum() != null) {
			necklinethrum += this.ctService.getDescription(CtArmorType.class.getName(),
					pi.getNecklineThrum().getCtArmorType(), locale)
					+ " ";
			necklinethrum += this.ctService.getDescription(
					CtArmor1Type.class.getName(), pi.getNecklineThrum()
							.getCtArmor1Type(), locale)
					+ " ";
			necklinethrum += pi.getNecklineThrum().getArmorTypeE() == null ? "" : (pi
					.getNecklineThrum().getArmorTypeE() + " ");
			necklinethrum += this.ctService.getDescription(CtArmorSet.class.getName(),
					pi.getNecklineThrum().getCtArmorSet(), locale)
					+ " ";
		}
		table.addCell(getTableCellBold(necklinethrum, 1, Rectangle.NO_BORDER));
		
		//3nd row
		table.addCell(getEmptyLine(1, Rectangle.BOTTOM));
		
		PdfPCell cell1 = null;
		if(pi.getFront() != null && pi.getFront().getPhoto1Name() != null){
			StringUtils.writeFile(super.realFileDir
					+ pi.getFront().getPhoto1Name(), pi.getFront().getPhoto1());
			cell1 = new PdfPCell(Image.getInstance(super.realFileDir
					+ pi.getFront().getPhoto1Name()), true);
		}else{
			cell1 = new PdfPCell(Image.getInstance(super.realFileDir
					+ "s.gif"), true);
		}
		cell1.setPadding(5);
		cell1.setBorder(Rectangle.BOTTOM);
		table.addCell(cell1);
		
		PdfPCell cell2 = null;
		if(pi.getBack() != null && pi.getBack().getPhoto1Name() != null){
			StringUtils.writeFile(super.realFileDir
					+ pi.getBack().getPhoto1Name(), pi.getBack().getPhoto1());
			cell2 = new PdfPCell(Image.getInstance(super.realFileDir
					+ pi.getBack().getPhoto1Name()), true);
		}else{
			cell2 = new PdfPCell(Image.getInstance(super.realFileDir
					+ "s.gif"), true);
		}
		cell2.setPadding(5);
		cell2.setBorder(Rectangle.BOTTOM);
		table.addCell(cell2);
		
		PdfPCell cell3 = null;
		if(pi.getSleeves() != null && pi.getSleeves().getPhoto1Name() != null){
			StringUtils.writeFile(super.realFileDir
					+ pi.getSleeves().getPhoto1Name(), pi.getSleeves().getPhoto1());
			cell3 = new PdfPCell(Image.getInstance(super.realFileDir
					+ pi.getSleeves().getPhoto1Name()), true);
		}else{
			cell3 = new PdfPCell(Image.getInstance(super.realFileDir
					+ "s.gif"), true);
		}
		cell3.setPadding(5);
		cell3.setBorder(Rectangle.BOTTOM);
		table.addCell(cell3);
		
		PdfPCell cell4 = null;
		if(pi.getBottomThrum() != null && pi.getBottomThrum().getPhoto1Name() != null){
			StringUtils.writeFile(super.realFileDir
					+ pi.getBottomThrum().getPhoto1Name(), pi.getBottomThrum().getPhoto1());
			cell4 = new PdfPCell(Image.getInstance(super.realFileDir
					+ pi.getBottomThrum().getPhoto1Name()), true);
		}else{
			cell4 = new PdfPCell(Image.getInstance(super.realFileDir
					+ "s.gif"), true);
		}
		cell4.setPadding(5);
		cell4.setBorder(Rectangle.BOTTOM);
		table.addCell(cell4);
		
		PdfPCell cell5 = null;
		if(pi.getSleevesThrum() != null && pi.getSleevesThrum().getPhoto1Name() != null){
			StringUtils.writeFile(super.realFileDir
					+ pi.getSleevesThrum().getPhoto1Name(), pi.getSleevesThrum().getPhoto1());
			cell5 = new PdfPCell(Image.getInstance(super.realFileDir
					+ pi.getSleevesThrum().getPhoto1Name()), true);
		}else{
			cell5 = new PdfPCell(Image.getInstance(super.realFileDir
					+ "s.gif"), true);
		}
		cell5.setPadding(5);
		cell5.setBorder(Rectangle.BOTTOM);
		table.addCell(cell5);
		
		PdfPCell cell6 = null;
		if(pi.getNecklineThrum() != null && pi.getNecklineThrum().getPhoto1Name() != null){
			StringUtils.writeFile(super.realFileDir
					+ pi.getNecklineThrum().getPhoto1Name(), pi.getNecklineThrum().getPhoto1());
			cell6 = new PdfPCell(Image.getInstance(super.realFileDir
					+ pi.getNecklineThrum().getPhoto1Name()), true);
		}else{
			cell6 = new PdfPCell(Image.getInstance(super.realFileDir
					+ "s.gif"), true);
		}
		cell6.setPadding(5);
		cell6.setBorder(Rectangle.BOTTOM);
		table.addCell(cell6);
		
		return table;
	}
	
	private PdfPTable getPiTitleTable14(ProductIdentification pi)
	throws Exception {
		// first page
		float[] widthsTitle = { 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f};
		PdfPTable table = new PdfPTable(widthsTitle);
		table.setWidthPercentage(100);
		table.setSpacingBefore(5);
		
		//1st row
		table.addCell(getEmptyLine(1, Rectangle.TOP));
		table.addCell(getTableCell("1", 1, Rectangle.TOP));
		table.addCell(getTableCell("2", 1, Rectangle.TOP));
		table.addCell(getTableCell("3", 1, Rectangle.TOP));
		table.addCell(getTableCell("4", 1, Rectangle.TOP));
		table.addCell(getTableCell("5", 1, Rectangle.TOP));
		
		List<ProductDZColor> pDZColorList = pi.getDiffProductDZColor();
		//2nd row
		table.addCell(getTableCell("ui.yarn.reference", 1, Rectangle.NO_BORDER));
		for (int i = 0; i < 5; i ++) {
			if(i < pDZColorList.size()){
				BiYarn biYarn = pDZColorList.get(i).getBiDZColor().getBiYarn();
				table.addCell(getTableCellBold(biYarn.getReference(), 1, Rectangle.NO_BORDER));
			}else{
				table.addCell(getEmptyLine(1, Rectangle.NO_BORDER));
			}
		}
		
		//3rd row
		table.addCell(getTableCell("ui.yarn.titrage", 1, Rectangle.NO_BORDER));
		for (int i = 0; i < 5; i ++) {
			if(i < pDZColorList.size()){
				BiYarn biYarn = pDZColorList.get(i).getBiDZColor().getBiYarn();
				table.addCell(getTableCellBold(new String[] {
					this.ctService.getDescription(CtYarnMeasure.class
							.getName(), biYarn.getCtYarnMeasure(), locale),
					biYarn.getYarnAccount() }, Rectangle.NO_BORDER, 1));
			}else{
				table.addCell(getEmptyLine(1, Rectangle.NO_BORDER));
			}
		}
		
		//4th row
		table.addCell(getTableCell("ui.yarn.composition", 1, Rectangle.NO_BORDER));
		for (int i = 0; i < 5; i ++) {
			if(i < pDZColorList.size()){
				BiYarn biYarn = pDZColorList.get(i).getBiDZColor().getBiYarn();
				String composition = "";
				if (!StringUtils.isEmpty(biYarn.getCtYarnMaterial1())) {
					composition += biYarn.getComposition1()
							+ "% "
							+ this.ctService.getDescription(
									CtYarnMaterial.class.getName(), biYarn
											.getCtYarnMaterial1(), locale)
							+ "  ";
				}
				if (!StringUtils.isEmpty(biYarn.getCtYarnMaterial2())) {
					composition += biYarn.getComposition2()
							+ "% "
							+ this.ctService.getDescription(
									CtYarnMaterial.class.getName(), biYarn
											.getCtYarnMaterial2(), locale)
							+ "  ";
				}
				if (!StringUtils.isEmpty(biYarn.getCtYarnMaterial3())) {
					composition += biYarn.getComposition3()
							+ "% "
							+ this.ctService.getDescription(
									CtYarnMaterial.class.getName(), biYarn
											.getCtYarnMaterial3(), locale)
							+ "  ";
				}
				if (!StringUtils.isEmpty(biYarn.getCtYarnMaterial4())) {
					composition += biYarn.getComposition4()
							+ "% "
							+ this.ctService.getDescription(
									CtYarnMaterial.class.getName(), biYarn
											.getCtYarnMaterial4(), locale)
							+ "  ";
				}
				if (!StringUtils.isEmpty(biYarn.getCtYarnMaterial5())) {
					composition += biYarn.getComposition5()
							+ "% "
							+ this.ctService.getDescription(
									CtYarnMaterial.class.getName(), biYarn
											.getCtYarnMaterial5(), locale)
							+ "  ";
				}
				table.addCell(getTableCellBold(composition, 1, Rectangle.NO_BORDER));
			}else{
				table.addCell(getEmptyLine(1, Rectangle.NO_BORDER));
			}
		}
		
		//5th row
		table.addCell(getTableCell(new String[] {
				"ui.productidentification.precentage", " (%)" }, Rectangle.BOTTOM, 1));
		for (int i = 0; i < 5; i ++) {
			if(i < pDZColorList.size()){
				table.addCell(getTableCellBold(pDZColorList.get(i).getPercentage().toString(), 1, Rectangle.BOTTOM));
			}else{
				table.addCell(getEmptyLine(1, Rectangle.BOTTOM));
			}
		}
		
		
		return table;
	}
	
	private PdfPTable getPiTitleTable15(ProductIdentification pi)
	throws Exception {
		// first page
		float[] widthsTitle = { 3.3f, 3.3f, 3.3f};
		PdfPTable table = new PdfPTable(widthsTitle);
		table.setWidthPercentage(100);
		table.setSpacingBefore(5);
		
		table.addCell(getTableCell(new String[]{"ui.productidentification.sketch", "1"}, Rectangle.TOP, 1));
		table.addCell(getTableCell(new String[]{"ui.productidentification.sketch", "2"}, Rectangle.TOP, 1));
		table.addCell(getTableCell(new String[]{"ui.productidentification.sketch", "3"}, Rectangle.TOP, 1));
		
		PdfPCell cell1 = null;
		if(pi.getSketch1() != null){
			StringUtils.writeFile(super.realFileDir
					+ pi.getSketch1Name(), pi.getSketch1());
			cell1 = new PdfPCell(Image.getInstance(super.realFileDir
					+ pi.getSketch1Name()), true);
		}else{
			cell1 = new PdfPCell(Image.getInstance(super.realFileDir
					+ "s.gif"), true);
		}
		cell1.setPaddingTop(5);
		cell1.setPaddingLeft(20);
		cell1.setPaddingRight(20);
		cell1.setPaddingBottom(5);
		cell1.setBorder(Rectangle.NO_BORDER);
		table.addCell(cell1);
		
		PdfPCell cell2 = null;
		if(pi.getSketch2() != null){
			StringUtils.writeFile(super.realFileDir
					+ pi.getSketch2Name(), pi.getSketch2());
			cell2 = new PdfPCell(Image.getInstance(super.realFileDir
					+ pi.getSketch2Name()), true);
		}else{
			cell2 = new PdfPCell(Image.getInstance(super.realFileDir
					+ "s.gif"), true);
		}
		cell2.setPaddingTop(5);
		cell2.setPaddingLeft(20);
		cell2.setPaddingRight(20);
		cell2.setPaddingBottom(5);
		cell2.setBorder(Rectangle.NO_BORDER);
		table.addCell(cell2);
		
		PdfPCell cell3 = null;
		if(pi.getSketch3() != null){
			StringUtils.writeFile(super.realFileDir
					+ pi.getSketch3Name(), pi.getSketch3());
			cell3 = new PdfPCell(Image.getInstance(super.realFileDir
					+ pi.getSketch3Name()), true);
		}else{
			cell3 = new PdfPCell(Image.getInstance(super.realFileDir
					+ "s.gif"), true);
		}
		cell3.setPaddingTop(5);
		cell3.setPaddingLeft(20);
		cell3.setPaddingRight(20);
		cell3.setPaddingBottom(5);
		cell3.setBorder(Rectangle.NO_BORDER);
		table.addCell(cell3);
		
		PdfPCell cell4 = null;
		if (Constants.LOCALE_TYPE_EN.equals(locale)) {
			cell4 = getTableCellBold(pi.getSketch1DescriptionEN(), true, 1);
		} else if (Constants.LOCALE_TYPE_ZH.equals(locale)) {
			cell4 = getTableCellBold(pi.getSketch1DescriptionCN(), true, 1);
		} else {
			cell4 = getTableCellBold(pi.getSketch1DescriptionFR(), true, 1);
		}
		cell4.setPaddingLeft(20);
		cell4.setPaddingRight(20);
		table.addCell(cell4);
		
		PdfPCell cell5 = null;
		if (Constants.LOCALE_TYPE_EN.equals(locale)) {
			cell5 = getTableCellBold(pi.getSketch2DescriptionEN(), true, 1);
		} else if (Constants.LOCALE_TYPE_ZH.equals(locale)) {
			cell5 = getTableCellBold(pi.getSketch2DescriptionCN(), true, 1);
		} else {
			cell5 = getTableCellBold(pi.getSketch2DescriptionFR(), true, 1);
		}
		cell5.setPaddingLeft(20);
		cell5.setPaddingRight(20);
		table.addCell(cell5);
		
		PdfPCell cell6 = null;
		if (Constants.LOCALE_TYPE_EN.equals(locale)) {
			cell6 = getTableCellBold(pi.getSketch3DescriptionEN(), true, 1);
		} else if (Constants.LOCALE_TYPE_ZH.equals(locale)) {
			cell6 = getTableCellBold(pi.getSketch3DescriptionCN(), true, 1);
		} else {
			cell6 = getTableCellBold(pi.getSketch3DescriptionFR(), true, 1);
		}
		cell6.setPaddingLeft(20);
		cell6.setPaddingRight(20);
		table.addCell(cell6);
		
		return table;
	}
	
	private PdfPTable getPiTitleTable16(ProductIdentification pi)
		throws Exception {
		// first page
		//float[] widthsTitle = { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f};
		float[] widthsTitle;
		if("tc".equals(input)){
			widthsTitle = new float[]{ 1f,0.5f, 1f, 1.5f, 1.1f, 1f, 0.5f, 0.6f, 0.6f, 0.6f, 1.5f };
		}else{
			widthsTitle = new float[]{ 1f,0.5f, 1f, 1.5f, 1.1f, 1f, 1f};
		}
		PdfPTable table5 = new PdfPTable(widthsTitle);
		table5.setWidthPercentage(100);
		table5.setSpacingBefore(5);
		
		table5.addCell(getTableCell("ui.dzcolor.variant", true, 1));
		table5.addCell(getTableCell("N°", true, 1));
		table5.addCell(getTableCell("ui.pantonecolor.customercolor", true, 1));
		table5.addCell(getTableCell("ui.order.dzcolor", true, 1));
		table5.addCell(getTableCell("ui.yarn.reference", true, 1));
		table5.addCell(getTableCell("ui.yarn.titrage", true, 1));
		table5.addCell(getTableCell(" % ", true, 1));
		//table5.addCell(getTableCell("ui.order.colortest", true, 1));
		if("tc".equals(this.input)){
			table5.addCell(getTableCell("ui.factory.pull1",
					true, 1));
			table5.addCell(getTableCell("ui.measurespecification.size",
					true, 1));
			table5.addCell(getTableCell("ui.productidentification.quantityswatch1",
					true, 1));
			table5.addCell(getTableCell(new String[]{"ui.dzcolor.actualweight", "(Kg)"}, true, 1));
		}
		List<String> variantList = this.dao.getDifferentVariant(pi.getId());

		Set<ProductDZColor> pDZColorSet = pi.getProductDZColors();
		Set<ProductLaunching> plSet = pi.getProductLaunchings();
		for (int i = 0; i < variantList.size(); i++) {
			int rowSpan = 0;
			for (ProductDZColor pDZColor1 : pDZColorSet) {
				if (variantList.get(i).equals(pDZColor1.getVariant())) {
					rowSpan++;
				}
			}
			PdfPCell cell51 = getTableCell(variantList.get(i), true, 1);
			cell51.setRowspan(rowSpan);
			table5.addCell(cell51);

			int hit = 0;
			for (ProductDZColor pDZColor : pDZColorSet) {
				if (variantList.get(i).equals(pDZColor.getVariant())) {
					table5.addCell(getTableCell(Integer.toString(pDZColor.getSequence()), true, 1));
					table5.addCell(getTableCell(pDZColor.getBiDZColor()
							.getCustomerColorCode(), true, 1));

					table5.addCell(getTableCell(pDZColor.getBiDZColor().getDzColorCode(), true, 1));
					table5.addCell(getTableCell(pDZColor.getBiDZColor().getBiYarn().getReference(), true, 1));
					table5.addCell(getTableCell(new String[] {
							this.ctService.getDescription(CtYarnMeasure.class
									.getName(), pDZColor.getBiDZColor().getBiYarn().getCtYarnMeasure(), locale),
									pDZColor.getBiDZColor().getBiYarn().getYarnAccount() }, true, 1));
					table5.addCell(getTableCell(pDZColor.getPercentage().toString(), true, 1));
					
//					OrderColorTest oct = colorServiceImpl.getColorText(pDZColor
//							.getBiDZColor());
//					if (oct == null) {
//						table5.addCell(getTableCell("", true, 1));
//					} else {
//						if ("01".equals(oct.getIsColorApproved())) {
//							table5.addCell(getTableCell(new String[] {
//									oct.getTestNumber(), "OK" }, true, 1));
//						} else {
//							table5.addCell(getTableCell("NO", true, 1));
//						}
//					}

					if (hit > 0) {
						continue;
					}
					if("tc".equals(input)){
						for (ProductLaunching productLaunching : plSet) {
							if (variantList.get(i).equals(
									productLaunching.getVariant())) {
								hit++;
								PdfPCell cell54 = getTableCell(productLaunching
										.getQuantity1() == null ? ""
										: productLaunching.getQuantity1()
												.toString(), true, 1);
								cell54.setRowspan(rowSpan);
								table5.addCell(cell54);
								
								String size;
								if("all".equals(productLaunching.getSize())){
									size = "ui.accessoryothers.forall";
								}else{
									size = productLaunching.getSize();
								}
								PdfPCell cell55 = getTableCell(size == null ? ""
										: productLaunching.getSize(), true, 1);
								cell55.setRowspan(rowSpan);
								table5.addCell(cell55);
	
								PdfPCell cell56 = getTableCell(productLaunching
										.getQuantity2() == null ? ""
										: productLaunching.getQuantity2()
												.toString(), true, 1);
								cell56.setRowspan(rowSpan);
								table5.addCell(cell56);
	
								double weight = productLaunching.getProductIdentification().getWeight() * productLaunching.getQuantity1();
								if(productLaunching.getQuantity2() != null){
									weight += productLaunching.getQuantity2() * 0.1;
								}
								PdfPCell cell57 = getTableCell(StringUtils.toNDigital(weight, 4), true, 1);
								cell57.setRowspan(rowSpan);
								table5.addCell(cell57);
								break;
							}
						}
						if (hit == 0) {
							hit++;
							PdfPCell cell54 = getTableCell("", true, 1);
							cell54.setRowspan(rowSpan);
							table5.addCell(cell54);
	
							PdfPCell cell55 = getTableCell("", true, 1);
							cell55.setRowspan(rowSpan);
							table5.addCell(cell55);
	
							PdfPCell cell56 = getTableCell("", true, 1);
							cell56.setRowspan(rowSpan);
							table5.addCell(cell56);
							
							PdfPCell cell57 = getTableCell("", true, 1);
							cell57.setRowspan(rowSpan);
							table5.addCell(cell57);
						}
					}
				}
			}

		}

		return table5;
	}
	
	private PdfPTable getPiTitleTable21(ProductIdentification pi)
		throws Exception {
		//first page
		float[] widthsTitle = { 1.0f, 1.0f };
		PdfPTable table = new PdfPTable(widthsTitle);
		table.setWidthPercentage(100);
		table.setSpacingBefore(5);
		//1st row
		if (pi.getBiMeasureSpecification().getRealPhoto1() != null) {
			StringUtils.writeFile(super.realFileDir
					+ pi.getBiMeasureSpecification().getRealPhoto1Name(), pi
					.getBiMeasureSpecification().getRealPhoto1());
			PdfPCell cell1 = new PdfPCell(Image.getInstance(super.realFileDir
					+ pi.getBiMeasureSpecification().getRealPhoto1Name()), true);
			cell1.setPaddingTop(5);
			cell1.setPaddingBottom(5);
			cell1.setPaddingLeft(50);
			cell1.setPaddingRight(25);
			cell1.setBorder(Rectangle.TOP);
			table.addCell(cell1);
		} else {
			table.addCell(getTableCell("", 1, Rectangle.TOP));
		}

		if (pi.getBiMeasureSpecification().getRealPhoto2() != null) {
			StringUtils.writeFile(super.realFileDir
					+ pi.getBiMeasureSpecification().getRealPhoto2Name(), pi
					.getBiMeasureSpecification().getRealPhoto2());
			PdfPCell cell2 = new PdfPCell(Image.getInstance(super.realFileDir
					+ pi.getBiMeasureSpecification().getRealPhoto2Name()), true);
			cell2.setPaddingTop(5);
			cell2.setPaddingBottom(5);
			cell2.setPaddingRight(50);
			cell2.setPaddingLeft(25);
			cell2.setBorder(Rectangle.TOP);
			table.addCell(cell2);
		} else {
			table.addCell(getTableCell("", 1, Rectangle.TOP));
		}
		return table;
	}
	
	private PdfPTable getHeader(BiMeasureSpecification biMS) throws Exception{
		float[] widthsTitle = { 0.5f, 0.2f, 0.2f, 0.3f, 0.3f, 0.3f};
		PdfPTable table = new PdfPTable(widthsTitle);
		table.setWidthPercentage(100);
		table.setSpacingBefore(2);
		//PdfPCell cellLeft = new PdfPCell();
//		cellLeft.setVerticalAlignment(Paragraph.ALIGN_LEFT);
//		cellLeft.setMinimumHeight(20);
//		cellLeft.setBorder(Rectangle.NO_BORDER);
//		cellLeft.setImage(Image.getInstance(super.realFileDir
//				+ "dzltd.png"));
		PdfPCell cell11 = getTableCellBoldBGGrey("ui.measurespecification.patronage", true, 1);
		table.addCell(cell11);
		
		PdfPCell cell12 = getTableCell(biMS.getPatronage(), true, 1);
		table.addCell(cell12);
		
		PdfPCell cell13 = getTableCellBoldBGGrey("message.edit.collar", true, 1);
		table.addCell(cell13);
		
		PdfPCell cell14 = getTableCell(this.ctService.getDescription(CtCollarType.class.getName(), biMS.getCtCollarType(), locale), true, 1);
		table.addCell(cell14);
		
		PdfPCell cell15 = getTableCellBoldBGGrey("ui.measurespecification.stature", true, 1);
		table.addCell(cell15);
		
		PdfPCell cell16 = getTableCell(this.ctService.getDescription(CtStature.class.getName(), biMS.getCtStature(), locale), true, 1);
		table.addCell(cell16);
		return table;
	}
	
	private PdfPTable getSkeletonImg(BiMeasureSpecification biMS) throws Exception{
		float[] widthsTitle = {0.5f, 0.5f};
		PdfPTable table = new PdfPTable(widthsTitle);
		table.setWidthPercentage(100);
		
		//table.addCell(getTableCell("", false, 1));
		if (biMS.getRealPhoto1() != null) {
			StringUtils.writeFile(super.realFileDir
					+ biMS.getRealPhoto1Name(), biMS.getRealPhoto1());
			Image photo1 = Image.getInstance(super.realFileDir
					+ biMS.getRealPhoto1Name());
			photo1.setWidthPercentage(0.6f);
			table.addCell(photo1);
		} else {
			table.addCell(getTableCell("", true, 1));
		}
		
		if (biMS.getRealPhoto2() != null) {
			StringUtils.writeFile(super.realFileDir
					+ biMS.getRealPhoto2Name(), biMS.getRealPhoto2());
			Image photo2 = Image.getInstance(super.realFileDir
					+ biMS.getRealPhoto2Name());
			photo2.setWidthPercentage(0.6f);
			table.addCell(photo2);
		} else {
			table.addCell(getTableCell("", true, 1));
		}
		//table.addCell(getTableCell("", false, 1));
		return table;
	}
	
	private PdfPTable getBiMeasureSpecificationTable(ProductIdentification pi)
	throws Exception {
		BiMeasureSpecification biMS = pi.getBiMeasureSpecification();
		String[] sizeNames = BiMeasureSpecificationServiceImpl.getSizeName(biMS.getCtStature());
		float[] widthsTitle;
		if("05".equals(biMS.getCtStature()) || "06".equals(biMS.getCtStature()) || "07".equals(biMS.getCtStature())){
			widthsTitle = new float[]{0.1f, 0.8f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.2f};
		}else if("04".equals(biMS.getCtStature()) ){
			widthsTitle = new float[]{0.1f, 0.8f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.2f};
		}else{
			widthsTitle = new float[]{0.1f, 0.8f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.2f};
		}
		PdfPTable table = new PdfPTable(widthsTitle);
		table.setWidthPercentage(100);
		
		table.addCell(getTableCellBoldBGGrey("N°", true, 1));
		table.addCell(getTableCellBoldBGGrey("ui.measurespecification.itemdesignations", true, 1));
		for(int i = 0; i < sizeNames.length; i ++){
			if(!"".equals(sizeNames[i])){
				if("05".equals(biMS.getCtStature()) || "06".equals(biMS.getCtStature()) || "07".equals(biMS.getCtStature())){
					table.addCell(getTableCellBoldBGGrey(sizeNames[i], true, 1));
				}else if("04".equals(biMS.getCtStature())){
					//do nothing
				}else{
					table.addCell(getTableCellBoldBGGrey(sizeNames[i], true, 2));
				}
			}
		}
		if("04".equals(biMS.getCtStature())){
			table.addCell(getTableCellBoldBGGrey(sizeNames[0], true, 2));
			table.addCell(getTableCellBoldBGGrey(sizeNames[3], true, 2));
			table.addCell(getTableCellBoldBGGrey(sizeNames[1], true, 2));
			table.addCell(getTableCellBoldBGGrey(sizeNames[4], true, 2));
			table.addCell(getTableCellBoldBGGrey(sizeNames[2], true, 2));
			table.addCell(getTableCellBoldBGGrey(sizeNames[5], true, 2));
		}
		table.addCell(getTableCellBoldBGGrey("ui.measurespecification.tolerance", true, 1));
		
		Set<ProductMeasureSpecificationItem> pMSItems = pi.getProductMeasureSpecificationItems();
		for (char j = 'A'; j <= 'U'; j++) {
			int hit = 0;
			for (ProductMeasureSpecificationItem pMSItem : pMSItems) {
				if (String.valueOf(j).equalsIgnoreCase(pMSItem.getNumber())) {
					hit++;
					table.addCell(getTableCell(String.valueOf(j), true, 1));
					table.addCell(getTableCell(this.ctService.getDescription(
							CtMsiDescription.class.getName(), pMSItem
									.getCtMsiDescription(), locale), true, 1));
					
					if("05".equals(biMS.getCtStature()) || "06".equals(biMS.getCtStature()) || "07".equals(biMS.getCtStature())){
						table.addCell(getTableCell(pMSItem.getSize1() == null ? ""
								: pMSItem.getSize1().toString(), true, 1));
						table.addCell(getTableCell(pMSItem.getSize2() == null ? ""
								: pMSItem.getSize2().toString(), true, 1));
						table.addCell(getTableCell(pMSItem.getSize3() == null ? ""
								: pMSItem.getSize3().toString(), true, 1));
						table.addCell(getTableCell(pMSItem.getSize4() == null ? ""
								: pMSItem.getSize4().toString(), true, 1));
						table.addCell(getTableCell(pMSItem.getSize5() == null ? ""
								: pMSItem.getSize5().toString(), true, 1));
						table.addCell(getTableCell(pMSItem.getSize6() == null ? ""
								: pMSItem.getSize6().toString(), true, 1));
						table.addCell(getTableCell(pMSItem.getSize7() == null ? ""
								: pMSItem.getSize7().toString(), true, 1));
						table.addCell(getTableCell(pMSItem.getSize8() == null ? ""
								: pMSItem.getSize8().toString(), true, 1));
					}else if("01".equals(biMS.getCtStature())){
						table.addCell(getTableCell(pMSItem.getSize2() == null ? ""
								: pMSItem.getSize2().toString(), true, 1));
						table.addCell(getTableCell("", true, 1));
						table.addCell(getTableCell(pMSItem.getSize3() == null ? ""
								: pMSItem.getSize3().toString(), true, 1));
						table.addCell(getTableCell("", true, 1));
						table.addCell(getTableCell(pMSItem.getSize4() == null ? ""
								: pMSItem.getSize4().toString(), true, 1));
						table.addCell(getTableCell("", true, 1));
						table.addCell(getTableCell(pMSItem.getSize5() == null ? ""
								: pMSItem.getSize5().toString(), true, 1));
						table.addCell(getTableCell("", true, 1));
						table.addCell(getTableCell(pMSItem.getSize6() == null ? ""
								: pMSItem.getSize6().toString(), true, 1));
						table.addCell(getTableCell("", true, 1));
					}else if("04".equals(biMS.getCtStature())){
						table.addCell(getTableCell(pMSItem.getSize1() == null ? ""
								: pMSItem.getSize1().toString(), true, 1));
						table.addCell(getTableCell("", true, 1));
						table.addCell(getTableCell(pMSItem.getSize4() == null ? ""
								: pMSItem.getSize4().toString(), true, 1));
						table.addCell(getTableCell("", true, 1));
						
						table.addCell(getTableCell(pMSItem.getSize2() == null ? ""
								: pMSItem.getSize2().toString(), true, 1));
						table.addCell(getTableCell("", true, 1));
						table.addCell(getTableCell(pMSItem.getSize5() == null ? ""
								: pMSItem.getSize5().toString(), true, 1));
						table.addCell(getTableCell("", true, 1));
						
						table.addCell(getTableCell(pMSItem.getSize3() == null ? ""
								: pMSItem.getSize3().toString(), true, 1));
						table.addCell(getTableCell("", true, 1));
						table.addCell(getTableCell(pMSItem.getSize6() == null ? ""
								: pMSItem.getSize6().toString(), true, 1));
						table.addCell(getTableCell("", true, 1));
//						table.addCell(getTableCell(pMSItem.getSize5() == null ? ""
//								: pMSItem.getSize5().toString(), true, 1));
//						table.addCell(getTableCell("", true, 1));
					}else{
						table.addCell(getTableCell(pMSItem.getSize1() == null ? ""
								: pMSItem.getSize1().toString(), true, 1));
						table.addCell(getTableCell("", true, 1));
						table.addCell(getTableCell(pMSItem.getSize2() == null ? ""
								: pMSItem.getSize2().toString(), true, 1));
						table.addCell(getTableCell("", true, 1));
						table.addCell(getTableCell(pMSItem.getSize3() == null ? ""
								: pMSItem.getSize3().toString(), true, 1));
						table.addCell(getTableCell("", true, 1));
						table.addCell(getTableCell(pMSItem.getSize4() == null ? ""
								: pMSItem.getSize4().toString(), true, 1));
						table.addCell(getTableCell("", true, 1));
						table.addCell(getTableCell(pMSItem.getSize5() == null ? ""
								: pMSItem.getSize5().toString(), true, 1));
						table.addCell(getTableCell("", true, 1));
					}
					table.addCell(getTableCell(
							pMSItem.getTolerance() == null ? ""
									: ("+/-" + pMSItem.getTolerance()
											.toString()), true, 1));
				}
			}
		}
		
		return table;
	}
	
	private PdfPTable getTrimmingListTable(ProductIdentification pi)
	throws Exception {
		float[] widthsTrimming = { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f};
		PdfPTable table7 = new PdfPTable(widthsTrimming);
		table7.setWidthPercentage(100);
		table7.setSpacingBefore(5);
		
		table7.addCell(getTableCell("ui.accessoryothers.reference", true,
				1));
		table7.addCell(getTableCell("ui.accessoryothers.type", true,
				1));
		table7.addCell(getTableCell("ui.accessoryothers.customerreference", true,
				1));
		table7.addCell(getTableCell("ui.accessoryothers.customercolor", true,
				1));
		table7.addCell(getTableCell("message.action.unitnumber", true,
				1));
		table7.addCell(getTableCell("ui.accessoryothers.forsize", true,
				1));
		table7.addCell(getTableCell("ui.dzcolor.variant", true,
				1));
		table7.addCell(getTableCell("message.edit.buyer", true,
				1));
		
		Set<ProductAccessoryOthers> paoSet = pi.getProductAccessoryOtherses();
		
		for (ProductAccessoryOthers productAccessoryOthers : paoSet) {
			if(productAccessoryOthers.getBiAccessoryOthers().getAccessoryReference() != null)
				table7.addCell(getTableCell(productAccessoryOthers.getBiAccessoryOthers().getAccessoryReference(), true, 1));
			else
				table7.addCell(getTableCell(productAccessoryOthers.getBiAccessoryOthers().getApplicationReference(), true, 1));
			if(productAccessoryOthers.getBiAccessoryOthers().getCtAccessoryType() != null)
				table7.addCell(getTableCell(this.ctService.getDescription(CtAccessoryType.class.getName(), productAccessoryOthers.getBiAccessoryOthers().getCtAccessoryType(), locale), true, 1));
			else
				table7.addCell(getTableCell(this.ctService.getDescription(CtApplicationType.class.getName(), productAccessoryOthers.getBiAccessoryOthers().getCtApplicationType(), locale), true, 1));
			table7.addCell(getTableCell(productAccessoryOthers.getBiAccessoryOthers().getCustomerReference(), true, 1));
			table7.addCell(getTableCell(productAccessoryOthers.getBiAccessoryOthers().getCustomerColor(), true, 1));
			table7.addCell(getTableCell(productAccessoryOthers.getUnitNumber().toString(), true, 1));
			if("all".equals(productAccessoryOthers.getForSize())){
				table7.addCell(getTableCell("ui.accessoryothers.forall", true, 1));
			}else{
				table7.addCell(getTableCell(productAccessoryOthers.getForSize(), true, 1));
			}
			if("all".equals(productAccessoryOthers.getVariant())){
				table7.addCell(getTableCell("ui.accessoryothers.forall", true, 1));
			}else{
				table7.addCell(getTableCell(productAccessoryOthers.getVariant(), true, 1));
			}
			
			table7.addCell(getTableCell(this.ctService.getDescription(CtSupplyType.class.getName(), productAccessoryOthers.getBiAccessoryOthers().getCtSupplyType(), this.locale), true, 1));
			
		}
		
		Set<ProductAccessoryButton> pabSet = pi.getProductAccessoryButtons();
		for(ProductAccessoryButton pab : pabSet){
			table7.addCell(getTableCell(pab.getBiAccessoryButton().getReference(), true, 1));
			table7.addCell(getTableCell("ui.productidentification.button", true, 1));
			table7.addCell(getTableCell(pab.getBiAccessoryButton().getCustomerReference(), true, 1));
			table7.addCell(getTableCell(pab.getBiAccessoryButton().getCustomerColor(), true, 1));
			table7.addCell(getTableCell(pab.getUnitNumber().toString(), true, 1));
			if("all".equals(pab.getForSize())){
				table7.addCell(getTableCell("ui.accessoryothers.forall", true, 1));
			}else{
				table7.addCell(getTableCell(pab.getForSize(), true, 1));
			}
			if("all".equals(pab.getVariant())){
				table7.addCell(getTableCell("ui.accessoryothers.forall", true, 1));
			}else{
				table7.addCell(getTableCell(pab.getVariant(), true, 1));
			}
			table7.addCell(getTableCell(this.ctService.getDescription(CtSupplyType.class.getName(), pab.getBiAccessoryButton().getCtSupplyType(), this.locale), true, 1));
		}
		
		Set<ProductAccessoryZip> pazSet = pi.getProductAccessoryZips();
		for(ProductAccessoryZip paz : pazSet){
			table7.addCell(getTableCell(paz.getBiAccessoryZip().getReference(), true, 1));
			table7.addCell(getTableCell("ui.factory.zip", true, 1));
			table7.addCell(getTableCell(paz.getBiAccessoryZip().getCustomerReference(), true, 1));
			table7.addCell(getTableCell(paz.getBiAccessoryZip().getCustomerColor(), true, 1));
			table7.addCell(getTableCell(paz.getUnitNumber().toString(), true, 1));
			if("all".equals(paz.getForSize())){
				table7.addCell(getTableCell("ui.accessoryothers.forall", true, 1));
			}else{
				table7.addCell(getTableCell(paz.getForSize(), true, 1));
			}
			if("all".equals(paz.getVariant())){
				table7.addCell(getTableCell("ui.accessoryothers.forall", true, 1));
			}else{
				table7.addCell(getTableCell(paz.getVariant(), true, 1));
			}
			table7.addCell(getTableCell(this.ctService.getDescription(CtSupplyType.class.getName(), paz.getBiAccessoryZip().getCtSupplyType(), this.locale), true, 1));
		}
		
		return table7;
	}
	
	private PdfPTable getTrimmingTable(ProductIdentification pi)
	throws Exception {
		float[] widthsTrimming = { 1f,1f, 1f, 1.5f, 1f, 3f, 2f };
		PdfPTable table7 = new PdfPTable(widthsTrimming);
		table7.setWidthPercentage(100);
		table7.setSpacingBefore(5);
		
		PdfPCell cell = getTableCell("ui.accessory.pose",true,7);
		table7.addCell(cell);
		
		PdfPCell cell10 = getTableCell("ui.accessoryothers.reference",
				true, 1);
		table7.addCell(cell10);
		
		PdfPCell cell102 = getTableCell("message.edit.photo",
				true, 1);
		table7.addCell(cell102);
		
		PdfPCell cell101 = getTableCell("ui.accessoryothers.type",
				true, 1);
		table7.addCell(cell101);
		
//		PdfPCell cell11 = getTableCell("", true, 1);
//		cell11.setRowspan(2);
//		table7.addCell(cell11);
		
		PdfPCell cell12 = getTableCell("message.edit.reference", true, 1);
		table7.addCell(cell12);
		
		PdfPCell cell13 = getTableCell("ui.productidentification.color", true,
				1);
		table7.addCell(cell13);
		
		/*PdfPCell cell14 = getTableCell(
				"ui.productidentification.quantitysweater", true, 1);
		cell14.setRowspan(2);
		table7.addCell(cell14);
		
		table7.addCell(getTableCell("ui.accessory.supplier", true, 2));
		*/
		PdfPCell cell16 = getTableCell("ui.accessory.pose", true, 1);
		table7.addCell(cell16);
		
		PdfPCell cell17 = getTableCell("message.edit.photo", true, 1);
		table7.addCell(cell17);
		
		
//		table7.addCell(getTableCell(new String[] {
//				pi.getBiFranceCustomer().getName(),
//				pi.getBiFranceCustomer().getDepartment() }, true, 1));
//		table7.addCell(getTableCell("DZ", true, 1));
		
		Set<ProductAccessoryHang> phtSet = pi.getProductAccessoryHangs();
		Set<ProductAccessoryOthers> paoSet = pi.getProductAccessoryOtherses();
		for (ProductAccessoryHang pht : phtSet) {
			table7.addCell(getTableCell(pht.getBiAccessoryOthers1()
					.getAccessoryReference(), true, 1));
			if (pht.getBiAccessoryOthers1().getPhoto1() != null) {
				StringUtils.writeFile(super.realFileDir
						+ pht.getBiAccessoryOthers1().getPhoto1Name(), pht
						.getBiAccessoryOthers1().getPhoto1());
				table7.addCell(Image.getInstance(super.realFileDir
						+ pht.getBiAccessoryOthers1().getPhoto1Name()));
			} else {
				table7.addCell(getTableCell("", true, 1));
			}
			
			table7.addCell(getTableCell(this.ctService.getDescription(
					CtAccessoryType.class.getName(), pht
							.getBiAccessoryOthers1().getCtAccessoryType(),
					locale), true, 1));
			
			table7.addCell(getTableCell(pht.getBiAccessoryOthers1().getCustomerReference(), true, 1));
			table7.addCell(getTableCell(pht.getBiAccessoryOthers1()
					.getCustomerColor(), true, 1));
		
			/*int hit = 0;
			for (ProductAccessoryOthers pao : paoSet) {
				if (pao.getBiAccessoryOthers().getId() == pht
						.getBiAccessoryOthers1().getId()) {
					hit++;
					table7.addCell(getTableCell(pao.getUnitNumber().toString(),
							true, 1));
					break;
				}
			}
			if (hit == 0) {
				table7.addCell(getTableCell("", true, 1));
			}
		
			
			if ("01".equals(pht.getBiAccessoryOthers1().getCtSupplyType())) {
				table7.addCell(getTableCell("X", true, 1));
				table7.addCell(getTableCell("", true, 1));
			} else {
				table7.addCell(getTableCell("", true, 1));
				table7.addCell(getTableCell("X", true, 1));
			}*/
			if (Constants.LOCALE_TYPE_EN.equals(locale)) {
				table7.addCell(getTableCell(pht.getDescriptionEN(), true, 1));
			} else if (Constants.LOCALE_TYPE_ZH.equals(locale)) {
				table7.addCell(getTableCell(pht.getDescriptionCN(), true, 1));
			} else {
				table7.addCell(getTableCell(pht.getDescriptionFR(), true, 1));
			}
			if (pht.getPhoto() != null) {
				StringUtils.writeFile(super.realFileDir + pht.getPhotoName(),
						pht.getPhoto());
				table7.addCell(Image.getInstance(super.realFileDir
						+ pht.getPhotoName()));
			} else {
				table7.addCell(getTableCell("", true, 1));
			}
		}
		return table7;
	}

	public String getInput() {
		return input;
	}

	public void setInput(String input) {
		this.input = input;
	}
}
